"""
兴趣相关模型
"""
from sqlalchemy import Column, BigInteger, String, Integer, Boolean, DateTime, ForeignKey, DECIMAL
from sqlalchemy.orm import relationship
from datetime import datetime
from database.base import Base


class InterestTag(Base):
    """兴趣标签表"""
    __tablename__ = "interest_tags"
    
    id = Column(BigInteger, primary_key=True, index=True, comment="兴趣ID")
    name = Column(String(50), unique=True, nullable=False, comment="兴趣名称")
    name_en = Column(String(100), comment="兴趣名称（英文）")
    description = Column(String(500), comment="描述")
    icon = Column(String(50), comment="图标emoji")
    color = Column(String(50), default="#007AFF", comment="颜色主题")
    sort_order = Column(Integer, default=0, index=True, comment="排序权重")
    status = Column(Integer, default=1, index=True, comment="状态")
    created_at = Column(DateTime, default=datetime.now, comment="创建时间")


class UserInterestTag(Base):
    """用户兴趣关联表"""
    __tablename__ = "user_interest_tags"
    
    id = Column(BigInteger, primary_key=True, index=True, comment="关联ID")
    user_id = Column(BigInteger, ForeignKey("users.id", ondelete="CASCADE"), nullable=False, index=True, comment="用户ID")
    interest_id = Column(BigInteger, ForeignKey("interest_tags.id", ondelete="CASCADE"), nullable=False, index=True, comment="兴趣ID")
    weight = Column(DECIMAL(3, 2), default=1.0, index=True, comment="权重")
    created_at = Column(DateTime, default=datetime.now, comment="创建时间")
    
    # 关联关系
    user = relationship("User", foreign_keys=[user_id], overlaps="user_interests")
    interest = relationship("InterestTag", foreign_keys=[interest_id])

